//
//  extension.swift
//  剂查查
//
//  Created by shoubin tao on 2024/12/7.
//  Copyright © 2024 shipin. All rights reserved.
//

import Foundation
import UIKit
extension UIImageView {
    func setImageUrl(url:String) {
        guard let url = URL(string: url) else { return }
        
        let task = URLSession.shared.dataTask(with: url) { [weak self] data, response, error in
            guard let data = data, error == nil else { return }
            DispatchQueue.main.async {
                self?.image = UIImage(data: data)
            }
        }
        task.resume()
    }
}
extension UIViewController {
    func popAction(){
        self.navigationController?.popViewController(animated: true)
    }
}

extension TimeInterval {
    func dateStr() ->String {
        let date = Date(timeIntervalSince1970: self)
        let formatter = DateFormatter()
        formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
        formatter.locale = Locale(identifier: "en_US_POSIX")
        formatter.timeZone = TimeZone(secondsFromGMT: 0) // 根据需要设置时区
        let dateString = formatter.string(from: date)
        return dateString
    }
}

extension CALayer {
    func setTopCorners( radius: CGFloat) {
        let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: [.topLeft, .topRight], cornerRadii: CGSize(width: radius, height: radius))
        let mask = CAShapeLayer()
        mask.path = path.cgPath
        self.mask = mask
    }
}
